#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int qx[]={0,0,1,-1};
const int qy[]={1,-1,0,0};
 
int n,m;
int head[105][105],tot;
struct aa {int x,y,pre;}a[200005];
void addedge(int g,int b,int c,int d) {a[++tot].x=c,a[tot].y=d;a[tot].pre=head[g][b];head[g][b]=tot;}
bool t1[105][105],t2[105][105],b[105][105];
queue<aa> q;
 
int main()
{
    scanf("%d%d",&n,&m);
    int gg,bb,cc,dd;
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d%d%d",&gg,&bb,&cc,&dd);
        addedge(gg,bb,cc,dd);
    }
     
    int ans=1;
     
    queue<aa> q;
     
    q.push((aa){1,1,0});
    t1[1][1]=t2[1][1]=true;
    while (!q.empty())
    {
        aa u=q.front();q.pop();
        int x=u.x,y=u.y;
        for (int i=head[x][y];i;i=a[i].pre)
        if (!t1[a[i].x][a[i].y])
        {
            if (t2[a[i].x][a[i].y]) 
                q.push((aa){a[i].x,a[i].y,0});
            t1[a[i].x][a[i].y]=true;ans++;  
        }
        for (int i=0;i<4;i++) 
        if (!t2[x+qx[i]][y+qy[i]])
        {
            if (t1[x+qx[i]][y+qy[i]])
                q.push((aa){x+qx[i],y+qy[i],0});
            t2[x+qx[i]][y+qy[i]]=true;
        }
    }
    printf("%d",ans);
    return 0;
}
